//
//  PostClass.m
//  Mecca
//
//  Created by Ryan Enguero on 5/20/14.
//  Copyright (c) 2014 TapDash Heuristics. All rights reserved.
//

#import "PostClass.h"

#import "Constant.h"

#import "JsonClass.h"

static PostClass *sharedItem = nil;

NSMutableData *homeData;

@implementation PostClass

#pragma mark - Register Method

- (NSMutableURLRequest*)registerMethodWithEmail:(NSString*)email andContactNumber:(NSString*)cNum andDisplayName:(NSString*)dName andCountry:(NSString*)country andPassword:(NSString*)password{
    
   // @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"email=%@&cnumber=%@&dname=%@&country=%@&password=%@",email, cNum, dName, country, password];
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:registerPost];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
   
    
//        NSError *error = [[NSError alloc] init];
//        NSHTTPURLResponse *response = nil;
//        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//    
//    
//    
//    
//        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    
      //  NSLog(@"Status Acknowledge = %@", returnData);
        
        return request;
        
    //}
    
}

#pragma mark - Login Method

- (NSMutableURLRequest*)loginWithUsername:(NSString*)username andPassword:(NSString*)password andDeviceID:(NSString*)deviceID{
    
    //@autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"email=%@&password=%@&device_id=%@",username, password, deviceID];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:loginPost];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
//        NSError *error = [[NSError alloc] init];
//        NSHTTPURLResponse *response = nil;
//        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
//        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    
    //    NSLog(@"Status Acknowledge = %@", returnData);
        
        return request;
        
  //  }
    
}

#pragma mark - Songs Details 

- (NSDictionary*)getSong:(NSString*)albumID andUserID:(NSString*)userID{
    
   // @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"album_id=%@&user_id=%@",albumID, userID];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:songsUrl];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
        NSError *error = [[NSError alloc] init];
        NSHTTPURLResponse *response = nil;
        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        
        NSDictionary *returnData = [JsonClass jsonParser:urlData];
        
            NSLog(@"song details = %@", returnData);
        
        return returnData;
        
   // }
    
}

- (NSMutableURLRequest*)getNewsfeed:(NSString*)deviceID{
    
   // @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@",deviceID];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:newsFeed];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
//    NSError *error = nil;
//        NSHTTPURLResponse *response = nil;
//    
//    
//        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
        
        
//        NSDictionary *returnData = [JsonClass jsonParser:urlData];
//        
//        NSLog(@"newsfeed details = %@", returnData);
    
//    if (error) {
////        NSLog(@"Error %@", [error localizedDescription]);
//        NSLog(@"Error");
//         return nil;
//    }else{
        return request;
//    }
    
    
//        return urlData;
    
   // }
    
}


- (NSMutableURLRequest*)getQRCodeLoad:(NSString*)qrCode andUserID:(NSString*)userID{
    
    // @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"qr_code=%@&user_id=%@",qrCode, userID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:qrCodeUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
    //    NSError *error = nil;
    //        NSHTTPURLResponse *response = nil;
    //
    //
    //        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    //    if (error) {
    ////        NSLog(@"Error %@", [error localizedDescription]);
    //        NSLog(@"Error");
    //         return nil;
    //    }else{
    return request;
    //    }
    
    
    //        return urlData;
    
    // }
    
}


- (NSMutableURLRequest*)getPlaylist:(NSString*)userID{
    
    // @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"user_id=%@",userID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:playList];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    return request;
 
    
}

#pragma mark - Download Count

- (NSDictionary*)downloadCount:(NSString*)songID andUserID:(NSString*)userID andPrice:(NSString*)price andUserCredits:(NSString*)userCredits andAlbumID:(NSString*)albumId{

   // @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"song_id=%@&user_id=%@&price=%@&user_credits=%@&album_id=%@",songID, userID, price, userCredits, albumId];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:downLoadSongCount];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
        NSError *error = [[NSError alloc] init];
        NSHTTPURLResponse *response = nil;
        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        
        NSDictionary *returnData = [JsonClass jsonParser:urlData];
        
        NSLog(@"download count = %@", returnData);
        
        return returnData;
        
   // }

}

#pragma mark - Tops 

- (NSMutableURLRequest*)getTops:(NSString*)deviceID andUserID:(NSString*)userID{
    
  //  @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@&user_id=%@",deviceID, userID];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:tops];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
//        NSError *error = [[NSError alloc] init];
//        NSHTTPURLResponse *response = nil;
//        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
//        NSDictionary *returnData = [JsonClass jsonParser:urlData];
//        
//        NSLog(@"newsfeed details = %@", returnData);
        
        return request;
        
   // }
    
}

#pragma mark - Albums

- (NSMutableURLRequest*)getAlbumsSchedsPhotos:(NSString*)artistID{
    
    //  @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"artist_id=%@",artistID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:albums];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    return request;
    
    // }
    
}

#pragma mark - Rate Song

- (NSData*)rateSongs:(NSMutableDictionary*)details{
//    song_id, user_id, rate
   // @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"song_id=%@&user_id=%@&rate=%@",[details objectForKey:@"song_id"], [details objectForKey:@"user_id"], [details objectForKey:@"rate"]];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:rate];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
        NSError *error = [[NSError alloc] init];
        NSHTTPURLResponse *response = nil;
        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        
        //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
        //
        //        NSLog(@"newsfeed details = %@", returnData);
        
        return urlData;
        
   // }
    
}

#pragma mark - Like

- (NSData*)likeSongs:(NSMutableDictionary*)details{
    //    song_id, user_id, rate
   // @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"song_id=%@&user_id=%@",[details objectForKey:@"song_id"], [details objectForKey:@"user_id"]];
        
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:likes_link];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
        NSError *error = [[NSError alloc] init];
        NSHTTPURLResponse *response = nil;
        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        
        //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
        //
        //        NSLog(@"newsfeed details = %@", returnData);
        
        return urlData;
        
  //  }
    
}

#pragma mark - Comment

- (NSData*)commentsPost:(NSMutableDictionary*)details{
    //    song_id, user_id, rate
    // @autoreleasepool {
    
    NSString *post =[[NSString alloc] initWithFormat:@"song_id=%@&user_id=%@&comment=%@",[details objectForKey:@"song_id"], [details objectForKey:@"user_id"], [details objectForKey:@"comment"]];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:comments];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
    NSError *error = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    return urlData;
    
    //  }
    
}

#pragma mark - Favorites

- (NSMutableURLRequest*)getFavorites:(NSString*)details andUserID:(NSString*)userID{

    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@&user_id=%@",details, userID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:favorites];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    return request;
    
    //  }

}


#pragma mark - Events 

- (NSMutableURLRequest*)getEvents:(NSString*)details{
    NSString *post =[[NSString alloc] initWithFormat:@"event_id=%@",details];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:eventUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    return request;
}

#pragma mark - Logout

- (NSMutableURLRequest*)logOutWithSessionID:(NSString*)sessionID{
    
    @autoreleasepool {
        NSString *post =[[NSString alloc] initWithFormat:@"sessionid=%@",sessionID];
        NSLog(@"PostData: %@",post);
        
        NSURL *url=[NSURL URLWithString:logoutUrl];
        
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        
        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
        
//        NSError *error = [[NSError alloc] init];
//        NSHTTPURLResponse *response = nil;
//        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//        
//        NSDictionary *returnData = [JsonClass jsonParser:urlData];
//        
//        NSLog(@"Log out = %@", returnData);
//        
//        return returnData;
        return  request;
        
    }
    
}

#pragma mark - Song View Comment 

- (NSData*)songViewComment:(NSString*)songID{
    
    //@autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"id=%@",songID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:viewComment];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
    NSError *error = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
   // NSDictionary *returnData = [JsonClass jsonParser:urlData];
    
    //    NSLog(@"Status Acknowledge = %@", returnData);
    
   
    
    return urlData;
    
    //  }
    
}

- (NSString*)updateProfile:(NSDictionary*)details{
    
    //@autoreleasepool {
    
    
    NSString *urlString = editProfileUrl;
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    
    NSMutableData *body = [NSMutableData data];
    
    

    
    
    // file
    NSData *imageData = UIImageJPEGRepresentation([details objectForKey:@"image"], 0.0);
    NSString *boundary = @"---------------------------14737809831466499882746641449";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    
    
    
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    // [body appendData:[NSString stringWithFormat:@"Location_ID = %@", locationID]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"%@.jpg\r\n", [details objectForKey:@"user_id"]] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
    //  parameter username
    //    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    //    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"location_id\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    //    [body appendData:[locationID dataUsingEncoding:NSUTF8StringEncoding]];
    //    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    //    [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    //    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"location_id\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    //    [body appendData:[[NSString stringWithFormat:@"%@",locationID] dataUsingEncoding:NSUTF8StringEncoding]];
    
    //  parameter token
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_id\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[details objectForKey:@"user_id"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
    //    //  parameter method
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_dname\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[details objectForKey:@"user_dname"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_password\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[details objectForKey:@"user_password"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_contact\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[details objectForKey:@"user_contact"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
    // close form
    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    // setting the body of the post to the reqeust
    
    [request setHTTPBody:body];
    
    // now lets make the connection to the web
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    // [self refreshResponse:returnString];
    
    //    SBJsonParser *jsonParser = [SBJsonParser new];
    //    self.jsonData = (NSDictionary *) [jsonParser objectWithString:returnString error:nil];
    //    NSLog(@"json %@",self.jsonData);
    //
    //    self.clientsDict = [[NSMutableDictionary alloc] init];
    //
    //    self.clientsDict = [self.jsonData objectForKey:@"clients"];
    
    NSLog(@"response = %@",returnString);
    
    return returnString;
    
    //
    
    
//    NSString *post = [[NSString alloc] initWithFormat:@"user_id=%@&user_dname=%@&user_contact=%@&user_password=%@&image=%@", [details objectForKey:@"user_id"],[details objectForKey:@"user_dname"],[details objectForKey:@"user_contact"],[details objectForKey:@"user_password"],[details objectForKey:@"image"]];
//
//    
////    NSString *post =[[NSString alloc] initWithFormat:@"user_id=%@&user_dname=%@&user_password=%@&user_image=%@",[details objectForKey:@"user_id"], [details objectForKey:@"user_dname"] ,[details objectForKey:@"user_password"] ,[details objectForKey:@"user_image"]];
//    
//    NSLog(@"PostData: %@",post);
//    
//    NSURL *url=[NSURL URLWithString:editProfileUrl];
//    
//    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//    
//    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
//    
//    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//    [request setURL:url];
//    [request setHTTPMethod:@"POST"];
//    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
//    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//    [request setHTTPBody:postData];
//    
//    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
//    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//    
//    // NSDictionary *returnData = [JsonClass jsonParser:urlData];
//    
//    //    NSLog(@"Status Acknowledge = %@", returnData);
//      NSString *returnString = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
//    
//    return returnString;
    
    //  }
    
}


#pragma facebook Login type;

- (NSDictionary*)postLoginType:(NSString*)loginType andFbID:(NSString*)fbID andUserDname:(NSString*)userdname andUserEmail:(NSString*)userEmail{
    
    // @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"login_type=%@&fb_id=%@&user_dname=%@&user_email=%@", loginType, fbID, userdname, userEmail];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:loginTypeUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
    NSError *error = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    NSDictionary *returnData = [JsonClass jsonParser:urlData];
    
    NSLog(@"Login Detail = %@", returnData);
    
    return returnData;
    
    // }
    
}


#pragma mark - New Artist


- (NSMutableURLRequest*)getNewArtist:(NSString*)deviceID{
    
    //  @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@",deviceID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:newArtistUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    return request;
    
    // }
    
}


#pragma mark New Song

- (NSMutableURLRequest*)getNewSong:(NSString*)deviceID andUserID:(NSString*)userID{
    
    //  @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@&user_id=%@",deviceID, userID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:newSongsUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
    //
    //        NSLog(@"newsfeed details = %@", returnData);
    
    return request;
    
    // }
    
}

#pragma mark Feature Artist

- (NSMutableURLRequest*)getFeaturedArtist:(NSString*)deviceID{
    
    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@",deviceID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:featuredArtistUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    return request;
    
    
//    //  @autoreleasepool {
//    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@",deviceID];
//    
//    NSLog(@"PostData: %@",post);
//    
//    NSURL *url=[NSURL URLWithString:featuredArtistUrl];
//    
//    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//    
//    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
//    
//    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//    [request setURL:url];
//    [request setHTTPMethod:@"POST"];
//    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
//    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//    [request setHTTPBody:postData];
//    
//    //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
//    
//    NSError *error = [[NSError alloc] init];
//    NSHTTPURLResponse *response = nil;
//    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//    
//    //        NSDictionary *returnData = [JsonClass jsonParser:urlData];
//    //
//    //        NSLog(@"newsfeed details = %@", returnData);
//    
//    return urlData;
//    
//    // }
    
}


#pragma mark Featured Song

- (NSMutableURLRequest*)getFeaturedSong:(NSString*)deviceID andUserID:(NSString*)userID{
    
    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@&user_id=%@",deviceID, userID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:featureSongUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    return request;
    
}


#pragma mark - Home

- (NSMutableURLRequest*)getHomeData:(NSString*)deviceID{
    
    //  @autoreleasepool {
    NSString *post =[[NSString alloc] initWithFormat:@"device_id=%@",deviceID];
    
    NSLog(@"PostData: %@",post);
    
    NSURL *url=[NSURL URLWithString:homeUrl];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    
    return request;

}

- (NSData*)dataHome{

    if (self.theConnection) {
    return homeData;
    }else{
    
        return nil;
    }
}



#pragma mark - SingleTon

+ (PostClass *)sharedItems
{
    if (sharedItem == nil) {
        sharedItem = [[super allocWithZone:NULL]init];
    }
    return  sharedItem;
}
- (id)init{
    if ((self = [super init])) {
        
    }
    return self;
}
+ (id)allocWithZone:(NSZone *)zone{
    return  [self sharedItems];
}
- (id)copyWithZone:(NSZone *)zone{
    return self;
}

@end
